home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
redakcyjne
/
programy
/
Tlen 6.0.1.12 pl
/
tleninst60112.exe
/
sdk
/
Plugin_src
/
protocol-vc
/
demoplugin.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2006-09-18
|
16KB
|
499 lines
// demoplugin.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "..\..\TlenSources\plugin\plugin_struct.h"
#include "..\..\TlenSources\plugin\plugin_protocol_defs.h"
#include "AggressiveOptimize.h"
#include "resource.h"
#include <stdlib.h>
#include <stdio.h>
HINSTANCE hInst;
TLENPLUGINFUNCTIONS *tlen_functions;
HWND window = NULL;
HANDLE tlen_hook, gg_hook;
TLENPLUGININFO pluginInfo={
sizeof(TLENPLUGININFO),
"Protocol demo",
PLUGIN_API_VERSION,
MAKE_DWORD_VERSION(1,0,0,1),
"Demonstracja funkcji protoko│≤w",
"⌐ Prawa autorskie",
"Producent",
"E@mail",
"http://www",
0,
0,
0,
0
};
extern "C" __declspec(dllexport) TLENPLUGININFO* GetPluginInfo(DWORD TlenVersion);
extern "C" __declspec(dllexport) int LoadPlugin(TLENPLUGINFUNCTIONS *tlen_functions);
extern "C" __declspec(dllexport) int UnloadPlugin(void);
void AddTextToWindow(int control_ID, char *prefix, char *text, int len)
{
if (text && len == 0) len = strlen(text);
HWND hw = GetDlgItem(window, control_ID);
int length = GetWindowTextLength(hw);
char *buf = (char *) malloc(length + 100 + len);
buf[length] = '\0';
GetWindowText(hw, buf, length + 100);
if (length) strcat(buf, "\r\n");
if (prefix)
{
strcat(buf, prefix);
strcat(buf, ": ");
}
if (text)
{
strcat(buf, text);
}
SetWindowText(hw, buf);
free(buf);
SendMessage(hw, EM_SETSEL, GetWindowTextLength(hw), GetWindowTextLength(hw));
SendMessage(hw, EM_SCROLLCARET, 0, 0);
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wparam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
return TRUE;
}
case WM_DESTROY:
{
window = NULL;
break;
}
case WM_CLOSE:
{
DestroyWindow(hWnd);
break;
}
case WM_COMMAND:
{
static int value;
switch (LOWORD(wparam))
{
case IDC_BUTTON3:
case IDC_BUTTON4:
{
HWND hw = GetDlgItem(hWnd, IDC_EDIT6);
int length = GetWindowTextLength(hw);
char *buf = (char *) malloc(length + 2);
buf[length] = '\0';
GetWindowText(hw, buf, length + 1);
ProtocolRawDataDef data;
InitializeStruct(data);
data.Data = buf;
data.DataLength = length;
if (LOWORD(wparam) == IDC_BUTTON3)
{
int ret;
CallTlenProtoFunction(hInst, PROTOCOL_ID_TLEN, PF_SENDRAWDATA, &data, NULL, ret);
}
else
{
int ret;
CallTlenProtoFunction(hInst, PROTOCOL_ID_TLEN, PF_FEEDRAWDATA, &data, NULL, ret);
}
free(buf);
break;
}
case IDC_BUTTON1:
{
char user[128];
char messg[1024];
char tlenp[] = PROTOCOL_ID_TLEN;
char ggp[] = PROTOCOL_ID_GG;
char *proto;
ProtocolMessageDef msg;
InitializeStruct(msg);
GetDlgItemText(hWnd, IDC_EDIT3, user, 127);
msg.Contact.ContactID = user;
(IsDlgButtonChecked(hWnd, IDC_RADIO1) == BST_CHECKED) ? proto = tlenp : proto = ggp;
msg.Contact.ProtocolID = proto;
GetDlgItemText(hWnd, IDC_EDIT4, messg, 1023);
msg.MessageText = messg;
msg.Flags = PROTOCOL_MESSAGE_FLAGS_CHAT;
int ret;
CallTlenProtoFunction(hInst, proto, PF_SENDMESSAGE, &msg, NULL, ret);
break;
}
case IDC_BUTTON2:
{
char status[128];
char tlenp[] = PROTOCOL_ID_TLEN;
char ggp[] = PROTOCOL_ID_GG;
char *proto;
ProtocolPresenceDef ps;
InitializeStruct(ps);
GetDlgItemText(hWnd, IDC_EDIT5, status, 127);
ps.CurrentDescription = status;
(IsDlgButtonChecked(hWnd, IDC_RADIO1) == BST_CHECKED) ? proto = tlenp : proto = ggp;
if (IsDlgButtonChecked(hWnd, IDC_RADIO4) == BST_CHECKED)
ps.CurrentState = PROTOCOL_PRESENCE_STATE_ONLINE;
if (IsDlgButtonChecked(hWnd, IDC_RADIO5) == BST_CHECKED)
ps.CurrentState = PROTOCOL_PRESENCE_STATE_OFFLINE;
if (IsDlgButtonChecked(hWnd, IDC_RADIO6) == BST_CHECKED)
ps.CurrentState = PROTOCOL_PRESENCE_STATE_AWAY;
if (IsDlgButtonChecked(hWnd, IDC_RADIO7) == BST_CHECKED)
ps.CurrentState = PROTOCOL_PRESENCE_STATE_INVISIBLE;
if (IsDlgButtonChecked(hWnd, IDC_RADIO8) == BST_CHECKED)
ps.CurrentState = PROTOCOL_PRESENCE_STATE_XA;
if (IsDlgButtonChecked(hWnd, IDC_RADIO9) == BST_CHECKED)
ps.CurrentState = PROTOCOL_PRESENCE_STATE_DND;
if (IsDlgButtonChecked(hWnd, IDC_RADIO10) == BST_CHECKED)
ps.CurrentState = PROTOCOL_PRESENCE_STATE_CHAT;
int ret;
CallTlenProtoFunction(hInst, proto, PF_CHANGEUSERSTATE, &ps, NULL, ret);
break;
}
case IDC_BUTTON5:
{
char tmp[128];
ProtocolPresenceDef prs;
int ret;
InitializeStruct(prs);
CallTlenProtoFunction(hInst, PROTOCOL_ID_GG, PF_GETUSERSTATE, &prs, NULL, ret);
AddTextToWindow(IDC_EDIT8, "USER STATE", NULL, 0);
sprintf(tmp, "%d", prs.CurrentState);
AddTextToWindow(IDC_EDIT8, "CurrentState", tmp, 0);
AddTextToWindow(IDC_EDIT8, "CurrentDesc", prs.CurrentDescription, 0);
CallTlenProtoFunction(hInst, PROTOCOL_ID_TLEN, PF_GETUSERSTATE, &prs, NULL, ret);
AddTextToWindow(IDC_EDIT1, "USER STATE", NULL, 0);
sprintf(tmp, "%d", prs.CurrentState);
AddTextToWindow(IDC_EDIT1, "CurrentState", tmp, 0);
AddTextToWindow(IDC_EDIT1, "CurrentDesc", prs.CurrentDescription, 0);
}
}
break;
}
}
return 0;
}
char *BinToHex(char *bin, int len)
{
char *buf = (char *) malloc(len * 3 + 1);
buf[0] = '\0';
char tmp[16];
for (int i = 0; i < len; i++)
{
sprintf(tmp, "%.2X ", (unsigned char) bin[i]);
strcat(buf, tmp);
}
return buf;
}
static int TlenProtocolEvent(WPARAM wparam, LPARAM lparam)
{
char tmp[128];
ProtocolEventDef *ev = (ProtocolEventDef *) wparam;
ProtocolRawDataDef *data = (ProtocolRawDataDef *) lparam;
ProtocolMessageDef *msg = (ProtocolMessageDef *) lparam;
ProtocolPresenceDef *prs = (ProtocolPresenceDef *) lparam;
ProtocolAuthRequestDef *auth = (ProtocolAuthRequestDef *) lparam;
ContactDef *ct = (ContactDef *) lparam;
switch (ev->EventID)
{
case PROTOCOL_EVENT_BEFORERECVRAWDATA:
AddTextToWindow(IDC_EDIT7, "BEFORERECVRAWDATA", data->Data, data->DataLength);
break;
case PROTOCOL_EVENT_AFTERRECVRAWDATA:
AddTextToWindow(IDC_EDIT7, "AFTERRECVRAWDATA", data->Data, data->DataLength);
break;
case PROTOCOL_EVENT_AFTERPROCESSEDRECVRAWDATA:
AddTextToWindow(IDC_EDIT7, "AFTERPROCESSEDRECVRAWDATA", data->Data, data->DataLength);
break;
case PROTOCOL_EVENT_BEFORESENDRAWDATA:
AddTextToWindow(IDC_EDIT7, "BEFORESENDRAWDATA", data->Data, data->DataLength);
break;
case PROTOCOL_EVENT_AFTERSENDRAWDATA:
AddTextToWindow(IDC_EDIT7, "AFTERSENDRAWDATA", data->Data, data->DataLength);
break;
case PROTOCOL_EVENT_LOGGEDIN:
AddTextToWindow(IDC_EDIT1, "LOGGEDIN", NULL, 0);
AddTextToWindow(IDC_EDIT1, "ContactID", ct->ContactID, 0);
break;
case PROTOCOL_EVENT_LOGGEDOUT:
AddTextToWindow(IDC_EDIT1, "LOGGEDOUT", NULL, 0);
AddTextToWindow(IDC_EDIT1, "ContactID", ct->ContactID, 0);
break;
case PROTOCOL_EVENT_RECVROSTER:
AddTextToWindow(IDC_EDIT1, "ROSTERRECV", NULL, 0);
break;
case PROTOCOL_EVENT_RECVMESSAGE:
case PROTOCOL_EVENT_BEFORESENDMESSAGE:
{
if (ev->EventID == PROTOCOL_EVENT_RECVMESSAGE)
AddTextToWindow(IDC_EDIT1, "MESSAGE RECV", NULL, 0);
else
AddTextToWindow(IDC_EDIT1, "BEFORE SEND MSG", NULL, 0);
AddTextToWindow(IDC_EDIT1, "ContactID", msg->Contact.ContactID, 0);
for (int i = 0; i < msg->MultipleContacts.count; i++)
AddTextToWindow(IDC_EDIT1, "ContactIDs", msg->MultipleContacts.contacts[i].ContactID, 0);
AddTextToWindow(IDC_EDIT1, "MessageID", msg->MessageID, 0);
AddTextToWindow(IDC_EDIT1, "Text", msg->MessageText, 0);
AddTextToWindow(IDC_EDIT1, "Room", msg->RoomName, 0);
AddTextToWindow(IDC_EDIT1, "Email", msg->UserEmail, 0);
AddTextToWindow(IDC_EDIT1, "Name", msg->UserName, 0);
AddTextToWindow(IDC_EDIT1, "WWW", msg->WWWGate, 0);
sprintf(tmp, "%d", msg->MessageHandle);
AddTextToWindow(IDC_EDIT1, "MsgHandle", tmp, 0);
sprintf(tmp, "%d", msg->Flags);
AddTextToWindow(IDC_EDIT1, "MsgFlags", tmp, 0);
sprintf(tmp, "%d", msg->OwnerData);
AddTextToWindow(IDC_EDIT1, "OwnerData", tmp, 0);
sprintf(tmp, "%d", msg->TimeStamp);
AddTextToWindow(IDC_EDIT1, "TimeStamp", tmp, 0);
break;
}
case PROTOCOL_EVENT_RECVPRESENCE:
case PROTOCOL_EVENT_BEFORESTATUSCHANGE:
if (ev->EventID == PROTOCOL_EVENT_RECVPRESENCE)
AddTextToWindow(IDC_EDIT1, "PRESENCE RECV", NULL, 0);
else
AddTextToWindow(IDC_EDIT1, "BEFORE STATUS CHANGE", NULL, 0);
AddTextToWindow(IDC_EDIT1, "ContactID", prs->Contact.ContactID, 0);
sprintf(tmp, "%d", prs->CurrentState);
AddTextToWindow(IDC_EDIT1, "CurrentState", tmp, 0);
AddTextToWindow(IDC_EDIT1, "CurrentDesc", prs->CurrentDescription, 0);
sprintf(tmp, "%d", prs->CurrentComeBackTimeStamp);
AddTextToWindow(IDC_EDIT1, "CurrentComeBackTimeStamp", tmp, 0);
sprintf(tmp, "%d", prs->PreviousState);
AddTextToWindow(IDC_EDIT1, "PreviousState", tmp, 0);
AddTextToWindow(IDC_EDIT1, "PreviousDesc", prs->PreviousDescription, 0);
sprintf(tmp, "%d", prs->PreviousComeBackTimeStamp);
AddTextToWindow(IDC_EDIT1, "PreviousComeBackTimeStamp", tmp, 0);
sprintf(tmp, "%d", prs->Flags);
AddTextToWindow(IDC_EDIT1, "Flags", tmp, 0);
sprintf(tmp, "%d", prs->OwnerData);
AddTextToWindow(IDC_EDIT1, "OwnerData", tmp, 0);
sprintf(tmp, "%d", prs->TimeStamp);
AddTextToWindow(IDC_EDIT1, "TimeStamp", tmp, 0);
break;
case PROTOCOL_EVENT_AUTHREQUEST:
AddTextToWindow(IDC_EDIT1, "AUTH REQUEST RECV", NULL, 0);
AddTextToWindow(IDC_EDIT1, "ContactID", prs->Contact.ContactID, 0);
break;
}
return 0;
}
static int GGProtocolEvent(WPARAM wparam, LPARAM lparam)
{
char tmp[128];
ProtocolEventDef *ev = (ProtocolEventDef *) wparam;
ProtocolRawDataDef *data = (ProtocolRawDataDef *) lparam;
ProtocolMessageDef *msg = (ProtocolMessageDef *) lparam;
ProtocolPresenceDef *prs = (ProtocolPresenceDef *) lparam;
ContactDef *ct = (ContactDef *) lparam;
switch (ev->EventID)
{
case PROTOCOL_EVENT_BEFORERECVRAWDATA:
{
char *dat = BinToHex(data->Data, data->DataLength);
int len = strlen(dat);
AddTextToWindow(IDC_EDIT2, "BEFORERECVRAWDATA", dat, len);
free(dat);
}
break;
case PROTOCOL_EVENT_AFTERRECVRAWDATA:
{
char *dat = BinToHex(data->Data, data->DataLength);
int len = strlen(dat);
AddTextToWindow(IDC_EDIT2, "AFTERRECVRAWDATA", dat, len);
free(dat);
}
break;
case PROTOCOL_EVENT_AFTERPROCESSEDRECVRAWDATA:
{
char *dat = BinToHex(data->Data, data->DataLength);
int len = strlen(dat);
AddTextToWindow(IDC_EDIT2, "AFTERPROCESSEDRECVRAWDATA", dat, len);
free(dat);
}
break;
case PROTOCOL_EVENT_BEFORESENDRAWDATA:
{
char *dat = BinToHex(data->Data, data->DataLength);
int len = strlen(dat);
AddTextToWindow(IDC_EDIT2, "BEFORESENDRAWDATA", dat, len);
free(dat);
}
break;
case PROTOCOL_EVENT_AFTERSENDRAWDATA:
{
char *dat = BinToHex(data->Data, data->DataLength);
int len = strlen(dat);
AddTextToWindow(IDC_EDIT2, "AFTERSENDRAWDATA", dat, len);
free(dat);
}
break;
case PROTOCOL_EVENT_LOGGEDIN:
AddTextToWindow(IDC_EDIT8, "LOGGEDIN", NULL, 0);
AddTextToWindow(IDC_EDIT8, "ContactID", ct->ContactID, 0);
break;
case PROTOCOL_EVENT_LOGGEDOUT:
AddTextToWindow(IDC_EDIT8, "LOGGEDOUT", NULL, 0);
AddTextToWindow(IDC_EDIT8, "ContactID", ct->ContactID, 0);
break;
case PROTOCOL_EVENT_RECVMESSAGE:
case PROTOCOL_EVENT_BEFORESENDMESSAGE:
{
if (ev->EventID == PROTOCOL_EVENT_RECVMESSAGE)
AddTextToWindow(IDC_EDIT8, "MESSAGE RECV", NULL, 0);
else
AddTextToWindow(IDC_EDIT8, "BEFORE SEND MSG", NULL, 0);
AddTextToWindow(IDC_EDIT8, "ContactID", msg->Contact.ContactID, 0);
for (int i = 0; i < msg->MultipleContacts.count; i++)
AddTextToWindow(IDC_EDIT8, "ContactIDs", msg->MultipleContacts.contacts[i].ContactID, 0);
AddTextToWindow(IDC_EDIT8, "MessageID", msg->MessageID, 0);
AddTextToWindow(IDC_EDIT8, "Text", msg->MessageText, 0);
AddTextToWindow(IDC_EDIT8, "Room", msg->RoomName, 0);
AddTextToWindow(IDC_EDIT8, "Email", msg->UserEmail, 0);
AddTextToWindow(IDC_EDIT8, "Name", msg->UserName, 0);
AddTextToWindow(IDC_EDIT8, "WWW", msg->WWWGate, 0);
sprintf(tmp, "%d", msg->MessageHandle);
AddTextToWindow(IDC_EDIT8, "MsgHandle", tmp, 0);
sprintf(tmp, "%d", msg->Flags);
AddTextToWindow(IDC_EDIT8, "MsgFlags", tmp, 0);
sprintf(tmp, "%d", msg->OwnerData);
AddTextToWindow(IDC_EDIT8, "OwnerData", tmp, 0);
sprintf(tmp, "%d", msg->TimeStamp);
AddTextToWindow(IDC_EDIT8, "TimeStamp", tmp, 0);
break;
}
case PROTOCOL_EVENT_RECVPRESENCE:
case PROTOCOL_EVENT_BEFORESTATUSCHANGE:
if (ev->EventID == PROTOCOL_EVENT_RECVPRESENCE)
AddTextToWindow(IDC_EDIT8, "PRESENCE RECV", NULL, 0);
else
AddTextToWindow(IDC_EDIT8, "BEFORE STATUS CHANGE", NULL, 0);
AddTextToWindow(IDC_EDIT8, "ContactID", prs->Contact.ContactID, 0);
sprintf(tmp, "%d", prs->CurrentState);
AddTextToWindow(IDC_EDIT8, "CurrentState", tmp, 0);
AddTextToWindow(IDC_EDIT8, "CurrentDesc", prs->CurrentDescription, 0);
sprintf(tmp, "%d", prs->CurrentComeBackTimeStamp);
AddTextToWindow(IDC_EDIT8, "CurrentComeBackTimeStamp", tmp, 0);
sprintf(tmp, "%d", prs->PreviousState);
AddTextToWindow(IDC_EDIT8, "PreviousState", tmp, 0);
AddTextToWindow(IDC_EDIT8, "PreviousDesc", prs->PreviousDescription, 0);
sprintf(tmp, "%d", prs->PreviousComeBackTimeStamp);
AddTextToWindow(IDC_EDIT8, "PreviousComeBackTimeStamp", tmp, 0);
sprintf(tmp, "%d", prs->Flags);
AddTextToWindow(IDC_EDIT8, "Flags", tmp, 0);
sprintf(tmp, "%d", prs->OwnerData);
AddTextToWindow(IDC_EDIT8, "OwnerData", tmp, 0);
sprintf(tmp, "%d", prs->TimeStamp);
AddTextToWindow(IDC_EDIT8, "TimeStamp", tmp, 0);
break;
}
return 0;
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
hInst=hinstDLL;
return TRUE;
}
__declspec(dllexport) TLENPLUGININFO* GetPluginInfo(DWORD tlenVersion)
{
return &pluginInfo;
}
__declspec(dllexport) int LoadPlugin(TLENPLUGINFUNCTIONS *functions)
{
tlen_functions = functions;
window = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC) WindowProc);
ProtocolHookDef th;
InitializeStruct(th);
th.ProtocolID = PROTOCOL_ID_TLEN;
th.CallBackFunc = TlenProtocolEvent;
th.moduleHandle = hInst;
tlen_hook = (HANDLE) tlen_functions->CallTlenFunction(hInst, TLEN_PROTOCOL_HOOK_EVENT, (WPARAM) &th, NULL);
th.ProtocolID = PROTOCOL_ID_GG;
th.CallBackFunc = GGProtocolEvent;
gg_hook = (HANDLE) tlen_functions->CallTlenFunction(hInst, TLEN_PROTOCOL_HOOK_EVENT, (WPARAM) &th, NULL);
return 0;
}
__declspec(dllexport) int UnloadPlugin(void)
{
tlen_functions->CallTlenFunction(hInst, TLEN_PROTOCOL_UNHOOK_EVENT, (WPARAM) PROTOCOL_ID_TLEN, (LPARAM) tlen_hook);
tlen_functions->CallTlenFunction(hInst, TLEN_PROTOCOL_UNHOOK_EVENT, (WPARAM) PROTOCOL_ID_GG, (LPARAM) gg_hook);
if (window) DestroyWindow(window);
return 0;
}